package 代码记录.指定公司代码练习记录.华为_2024.分值100.第36start;

import java.util.Scanner;

/**
 * @author zx
 * @create 2024-02-16 13:15
 * 基础二分查找(忘完了)
 */
public class 小明找位置_55 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] inputs = scanner.nextLine().split(",");
        int[] arr = new int[inputs.length];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = Integer.parseInt(inputs[i]);
        }
        int target = scanner.nextInt();
        // 使用二分查找找到小明应该插入的位置
        int pos = search(arr, target);
        // 输出位置(从1开始)
        System.out.println(pos + 1);
    }
    private static int search(int[] arr, int target) {
        int left = 0, right = arr.length - 1;
        while (left <= right) {
            int mid = left + ((right - left) >> 1);
            if (arr[mid] < target) {
                left = mid + 1;
            } else if (arr[mid] > target) {
                right = mid - 1;
            } else {
                return mid;
            }
        }
        return left;
    }
}
